<?php

namespace addons\zzyy\module;

use app\admin\model\zzyy\ZzyyReserve;
use app\admin\model\zzyy\ZzyyUserExtend;

class User
{
    static public function getUserInfo($uid)
    {
        $user = \app\admin\model\User::get($uid);

        $balance = ZzyyUserExtend::where('user_id', $uid)->find()->balance;

        $reserveCount = ZzyyReserve::where('user_id', $uid)
            ->where('status', ZzyyReserve::STATUS_SUCCESS)
            ->where('endtime', '>', Ykxbon::now()->toDateTimeString())
            ->order('starttime', 'asc')
            ->count();

        $info = [
            'user_id' => $user->id,
            'avatar' => cdnurl($user->avatar, true),
            'nickname' => $user->nickname,
            'gender' => $user->gender,
            'mobile' => $user->mobile,
            'birthday' => $user->birthday ? $user->birthday : '',
            'balance' => $balance,
            'uncomplete_order_count' => $reserveCount,
        ];

        return $info;
    }

}